package com.sskj.api.handler.introspector;

import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.AnnotationIntrospector;
import com.fasterxml.jackson.databind.introspect.Annotated;
import com.sskj.api.annotation.WithDomain;
import com.sskj.api.handler.serializer.WithDomainDeserializer;
import com.sskj.api.handler.serializer.WithDomainSerializer;

public class WithDomainAnnotationIntrospector extends AnnotationIntrospector {

    private final String domain;

    public WithDomainAnnotationIntrospector(String domain) {
        this.domain = domain;
    }

    @Override
    public Version version() {
        return Version.unknownVersion();
    }

    @Override
    public Object findSerializer(Annotated am) {
        if (am.hasAnnotation(WithDomain.class)) {
            return new WithDomainSerializer(domain);
        }
        return null;
    }

    @Override
    public Object findDeserializer(Annotated am) {
        if (am.hasAnnotation(WithDomain.class)) {
            return new WithDomainDeserializer(domain);
        }
        return null;
    }
}
